# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=guestfs-tools
pkgver=1.48.3
pkgrel=1
pkgdesc="Tools for accessing and modifying guest disk images"
arch=(loong64 x86_64)
url="http://libguestfs.org/"
license=(GPL2 LGPL2.1)
depends=(gcc-libs glibc jansson openssl perl-libintl-perl)
makedepends=(bash-completion cdrtools libguestfs libisoburn libvirt libxml2 ncurses ocaml-findlib perl-module-build xz)
checkdepends=(linux rpm-tools)
backup=(
  etc/virt-builder/repos.d/libguestfs.conf
  etc/virt-builder/repos.d/libguestfs.gpg
  etc/virt-builder/repos.d/opensuse.conf
  etc/virt-builder/repos.d/opensuse.gpg
)
options=(debug)
source=(http://download.libguestfs.org/$pkgname/${pkgver%.*}-stable/$pkgname-$pkgver.tar.gz{,.sig})
sha512sums=('2431be9bf5f1acff46e4be1ca202fd93f993666e2cf540166f8268dce9427bb102402a47fd7b738154304c08674dce9cbc7ba1bd1ac8c12c38a138bdca5cfee7'
            'SKIP')
b2sums=('c23ef70dfb09a3723e68ce74dbb91450de30fe8f67139ba941bbcf7816f137eab3b0960307d15660cf0d65c66d377b7d1d3b01f8821362ee3e320245af1afc08'
        'SKIP')
validpgpkeys=('F7774FB1AD074A7E8C8767EA91738F73E1B768A0')  # Richard W.M. Jones <rjones@redhat.com>

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc
  make
}

check() {
  export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1  # verbose libguestfs output
  export SKIP_TEST_VIRT_FILESYSTEMS_SH=1  # mismatch in test 2
  export SKIP_TEST_VIRT_INSPECTOR_SH=1  # requires KVM
  export SKIP_TEST_VIRT_INSPECTOR_LUKS_ON_LVM_SH=1  # requires KVM
  export SKIP_TEST_VIRT_INSPECTOR_LVM_ON_LUKS_SH=1  # requires KVM
  export SKIP_TEST_VIRT_BUILDER_SH=1  # virt-resize: error: /dev/sda2: physical volume not returned by pvs_full
  
  make -k check -C $pkgname-$pkgver
}

package() {
  depends+=(
    libguestfs libguestfs.so
    libvirt libvirt.so
    libxml2 libxml2.so
    ncurses libncursesw.so
    pcre2 libpcre2-8.so
    xz liblzma.so
  )

  make DESTDIR="$pkgdir/" install -C $pkgname-$pkgver
}
